(defparameter *license* "/*
 * Copyright 2007 National Bioinformatics Network
 * 
 * Licensed under the Apache License, Version 2.0 (the \"License\");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an \"AS IS\" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */")

(defun insert-license (filename)
  (let ((lines nil))
    ;; Save the current file
    (with-open-file (in filename :if-does-not-exist nil)
      (setf lines (loop for line = (read-line in nil) 
		     while line collect
		     line)))
    ;; Prepend the license and output the saves lines again
    (with-open-file (out filename :direction :output :if-exists :supersede)
      (write-line *license* out)
      (dolist (line lines)
	(write-line line out)))))

(defun insert-missing-license (java-files-filename)
  "Inserts the missing license into the Java files. If the second
line of the Java file doesn't contain the second line of the license,
the license is inserted. The file containing the java filenames is generated
with 'find . -name \"*.lisp\" > filename.txt"
  (with-open-file (java-files java-files-filename :if-does-not-exist nil)
    (loop for filename = (read-line java-files nil)
       while filename do
	 (with-open-file (java-file filename :if-does-not-exist nil)
	   (let ((first-line (read-line java-file nil))
		 (second-line (read-line java-file nil)))
	     (declare (ignorable first-line))
	     (if (not (search "National Bioinformatics Network" second-line))
		 (insert-license filename)))))))